﻿
Namespace PL.MESSDK
    Public Class MRPRevision_PL
        Inherits PLBase

        Public Sub New()
            MyBase.New()
        End Sub

        Public Sub New(ByVal queryName As String)
            MyBase.New(queryName)
        End Sub

        Public Overrides Sub ValidateRow(row As DataRow)
            row.ClearErrors()
            'Mandatory Fields
            'TODO: Cache MetaString in AppManager, so here we read it once maybe for nothing
            'Dim ms As MetaString
            'ms = MetaString.GetMetaStringByCode("Mandatory", AppManager.ApplicationOption.LanguageId)
            If IsDBNull(row("MRPRevID")) Then
                row.SetColumnError("MRPRevID", "Mandatory")
            End If
            If IsDBNull(row("MRPID_FK")) Then
                row.SetColumnError("MRPID_FK", "Mandatory")
            End If
            If IsDBNull(row("UsageID_FK")) Then
                row.SetColumnError("UsageID_FK", "Mandatory")
            End If
            If IsDBNull(row("IsActivated")) Then
                row.SetColumnError("IsActivated", "Mandatory")
            End If

            If row.HasErrors Then
                row.RowError = "Please check your columns, a validation error occur"
            End If
        End Sub

        Public Overrides Function Delete() As Boolean
            'Throw New NotImplementedException("Delete To Come...")
            Return False
        End Function

        Public Overrides Function Validate() As Boolean
            'Throw New NotImplementedException("Validate To Come...")
            Return True
        End Function


        Public Overridable Sub CopyToNewRevision(ByVal MRPRevID As Guid)
            Dim sqlcmd As System.Data.SqlClient.SqlCommand = Nothing

            Try
                sqlcmd = MetaQuery.GetSPCmdByMetaName("MRPRevision_Express_CopyFrom")

                sqlcmd.Parameters("@MRPRevID").Value = MRPRevID

                sqlcmd.ExecuteReader(CommandBehavior.CloseConnection)

            Catch sqlex As System.Data.SqlClient.SqlException
                Throw sqlex
            Finally
                If sqlcmd IsNot Nothing Then
                    sqlcmd.Connection.Close()
                    sqlcmd.Dispose()
                End If
            End Try
        End Sub

    End Class
	End Namespace
